<template>
  <div>
    <el-row>
      <el-col :span="16">

        <el-descriptions class="margin-top" :title="'线索ID'+id" :column="3" border>

          <template slot="extra">
            <el-button type="primary" size="small">操作</el-button>
          </template>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              创建时间
            </template>
            {{ clue.createTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-mobile-phone"></i>
              手机号
            </template>
            {{ clue.phone }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-location-outline"></i>
              渠道来源
            </template>
            {{ selectDictLabel(dict.type.clues_item, this.clue.channel) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-tickets"></i>
              线索归属
            </template>
            <el-tag size="small">{{ clue.guishu }}</el-tag>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              联系地址
            </template>
            江苏省苏州市吴中区吴中大道 1188 号
          </el-descriptions-item>
        </el-descriptions>
        <el-button type="danger" @click="falseClue">伪线索</el-button>
        <el-button type="success" @click="tranformBusiness">转商机</el-button>

        <el-divider></el-divider>
        <el-form ref="form" :disabled="disabled" :model="form" :rules="rules" label-width="110px">
          <el-row :gutter="5">
            <el-col :span="8">
              <el-form-item label="客户姓名" prop="name">
                <el-input v-model="form.name" placeholder="请输入客户姓名"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="性别" prop="sex">
                <el-select v-model="form.sex" placeholder="请选择性别">
                  <el-option
                    v-for="dict in dict.type.sys_user_sex"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="年龄" prop="age">
                <el-input v-model="form.age" type="number" placeholder="请输入年龄"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="8">
              <el-form-item label="微信号" prop="weixin">
                <el-input v-model="form.weixin" placeholder="请输入微信号"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="qq号" prop="qq">
                <el-input v-model="form.qq" placeholder="请输入qq号"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="意向等级" prop="level">
                <el-select v-model="form.level" placeholder="请输入意向等级">
                  <el-option
                    v-for="dict in dict.type.clues_level"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="8">
              <el-form-item label="意向学科" prop="subject">
                <el-select v-model="form.subject" placeholder="请输入意向学科">
                  <el-option
                    v-for="dict in dict.type.course_subject"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="下次跟进时间" prop="nextTime">
                <el-date-picker
                  v-model="form.nextTime"
                  type="datetime"
                  placeholder="下次跟进时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="24">
              <el-form-item label="跟进记录" prop="record">
                <el-input v-model="form.record" type="textarea" placeholder="请输入跟进记录"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col>
            <el-form-item>
              <el-button type="primary" @click="submitClue">保存</el-button>
              <el-button>重置</el-button>
            </el-form-item>
          </el-col>

        </el-form>
      </el-col>
      <el-col :span="8">
        <track-list ref="tralist" :id="id"></track-list>
      </el-col>
    </el-row>

    <false-clue ref="falseClue" @success="op"></false-clue>

  </div>
</template>

<script>
import {clueAdd, getClue} from "@/api/crm/clue";
import clue from "@/views/crm/clue/index.vue";
import TrackList from "@/views/crm/clue/components/track-list.vue";
import {selectDictLabel} from "../../../../utils/ruoyi";
import FalseClue from "@/views/crm/clue/components/false-clue";
import {formbusiness} from "@/api/crm/clue";

export default {
  name: "track-index",
  dicts: ["clues_item", "sys_user_sex", "course_subject", "clues_level"],
  components: {TrackList, FalseClue},
  props: {
    clueId: {
      type: [String, Number],
    }
  },
  data() {
    return {
      id: this.clueId,
      clue: {},
      form: {},
      rules: {},
    }
  },
  watch: {
    clueId(newValue, oldValue) {
      this.id = newValue
      this.$refs.tralist.id = this.id
      this.$refs.tralist.getTrackList();
      this.getlist();
    }
  },
  created() {
    this.getlist();
  }, methods: {
    selectDictLabel,
    getlist() {
      getClue(this.id).then(resu => {
        this.clue = resu.data;
        this.form = resu.data;
      })
    }, submitClue(row) {
      clueAdd(this.form).then(data => {
        this.$refs.tralist.id = this.id
        this.$refs.tralist.getTrackList();
        this.$modal.msgSuccess("操作成功")
        this.$emit("formbusok")
      })
    }, falseClue(row) {
      this.$refs.falseClue.open = true;
      this.$refs.falseClue.id = this.id
      this.$refs.falseClue.restform()
    }, op() {
      this.$refs.tralist.getTrackList()
    }, tranformBusiness() {
      this.$msgbox.confirm(`确定转换线索${this.id}到商机吗`).then(() => {
        formbusiness({id: this.id, recond: '转商机'}).then(data => {
          this.$modal.msgSuccess("转换商机成功");
          this.$refs.tralist.getTrackList();
          this.$emit("ok")
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
